// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
     //顶栏显示，上滑消失下滑出现
     statusBarHeight:0,
     navheight:0,
     pagetop:0,
     scrollTop:0, 
     numop:0 ,
     tuijian:[{
      id:1,
      img1:'/tupian/xc/top2.webp',
      img1:'/tupian/xc/top2.webp',
      text1:"女童粉系印花滑板",
      text2:5,
      text3:"活动价参考价",
      text4:3
     }],
    // top榜单
    toplist:[
      {
        id:2,
        img:'/tupian/xc/top2.webp',
        text1:"女童粉系印花滑板",
        text2:5,
        text3:"活动价参考价",
        text4:3
      },
      {
        id:3,
        img:'/tupian/xc/top2.webp',
        text1:"女童粉系印花滑板",
        text2:5,
        text3:"活动价参考价",
        text4:3
      },
      {
        id:4,
        img:'/tupian/xc/top2.webp',
        text1:"女童粉系印花滑板",
        text2:5,
        text3:"活动价参考价",
        text4:3
      },
      {
        id:5,
        img:'/tupian/xc/top2.webp',
        text1:"女童粉系印花滑板",
        text2:5,
        text3:"活动价参考价",
        text4:3
      },

    ]



  },



  onPageScroll(e) {//页面滚动就会触发
    this.setData({
      scrollTop:e.scrollTop
    })
  },



  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },

  onLoad: function (options) {

    wx.request({
      url: 'http://localhost:80/articles/top',
      method:"POST",
      header:{
        'content-type': 'application/x-www-form-urlencoded'
      },
      success:res=>{
        console.log(res.data.data)
        this.setData({
          toplist:res.data.data
        })
        console.log(this.data.toplist)
      }
    })
    






    // 顶部导航栏
    this.setData({
      //状态栏的高度
     statusBarHeight:wx.getSystemInfoSync()['statusBarHeight'] + 'px',
      //胶囊的高度 也就是自定导航栏的高度
     navheight:wx.getMenuButtonBoundingClientRect()['height'] + 'px',
      //状态栏加导航栏的高度 加上下的padding的高度 12
      pagetop:wx.getMenuButtonBoundingClientRect()['height'] + wx.getSystemInfoSync()['statusBarHeight'] + 12 + 'px',
   })

   if (wx.getUserProfile) {
    this.setData({
      canIUseGetUserProfile: true
    })
  }
  if (!wx.getStorageSync('userInfo')){
    wx.reLaunch({
       url: '/pages/weixingshouquan/weixingshouquan'
   })
  }

  },
  sousuo:function(){
    wx.navigateTo({
      url: '/pages/sousuo/sousuo',
    })
  },
  // 分类
  fenlei1:function(){
    wx.navigateTo({
      url: '/pages/ageleibie/ageleibie?type=0',
    })
  },
  fenlei2:function(){
    wx.navigateTo({
      url: '/pages/ageleibie/ageleibie?type=1',
    })
  },
  fenlei3:function(){
    wx.navigateTo({
      url: '/pages/ageleibie/ageleibie?type=2',
    })
  },
  fenlei4:function(){
    wx.navigateTo({
      url: '/pages/ageleibie/ageleibie?type=3',
    })
  },
  // 物品详情
  xiangqing:function(e){
    console.log(e)
    wx.navigateTo({
      url: '/pages/xiangqing/xiangqing?b='+JSON.stringify(this.data.toplist[e.currentTarget.dataset.index]),
    })
  },
  xiangqing1:function(){
    wx.request({
      url: 'http://localhost:80/articles/id',
      method:"POST",
      data:{
          id:24
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
      },
      success:res=>{
        console.log(res.data.data)
        wx.navigateTo({
          url: '/pages/xiangqing/xiangqing?b='+JSON.stringify(res.data.data[0]),
        })
      }
    })
    
  },
  xiangqing2:function(){
    wx.request({
      url: 'http://localhost:80/articles/id',
      method:"POST",
      data:{
          id:23
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
      },
      success:res=>{
        console.log(res.data.data)
        wx.navigateTo({
          url: '/pages/xiangqing/xiangqing?b='+JSON.stringify(res.data.data[0]),
        })
      }
    })
  },
  // 视频浏览
  shiping:function(){
    wx.navigateTo({
      url: '/pages/shiping/shiping?category=1',
    })
  },
  Allshiping:function(){
    wx.navigateTo({
      url: '/pages/shiping/shiping?category=0',
    })
  },
  

})
